1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : common/classes/class.bbcode.inc.php
5 : - Modulgruppe: Framework
6 : - Beschreibung: Umwandeln von BBCode und Smilies in HTML.
7 : - Version: 0.10.2, 20/01/09
8 : - Autor(en): Clemens Weiß <clemens.weiss@mni.fh-giessen.de>
9 : Daniel Knapp <damiel.knapp@mni.fh-giessen.de>
10 : +---------------------------------------------------------------------------+
11 : This program is free software; you can redistribute it and/or
12 : modify it under the terms of the GNU General Public License
13 : as published by the Free Software Foundation; either version 2
14 : of the License, or any later version.
15 : +---------------------------------------------------------------------------+
16 : This program is distributed in the hope that it will be useful,
17 : but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : GNU General Public License for more details.
20 : You should have received a copy of the GNU General Public License
21 : along with this program; if not, write to the Free Software
22 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 : +--------------------------------------------------------------------------*/
24 : /**
25 : * Umwandeln von BBCode und Smilies in HTML.
26 : * @package eStudy.Framework
27 : * @version 0.10.1, 27/01/07
28 : * @author Clemens Weiß <clemens.weiss@mni.fh-giessen.de>
29 : */
30 1 : require_once ("class.stringparser_bbcode.inc.php");
31 1 : require_once ("class.geshi.inc.php");
32 1 : require_once ("class.spellchecker.inc.php");
33 1 : class BBCode {
34 : /**
35 : * Enthält das Objekt des BBCode-Parsers
36 : * @access private
37 : * @var object
38 : */
39 : var $bbcode;
40 : /**
41 : * Enthält das GeSHi-Objekt für Syntax-Highlighting
42 : * @access private
43 : * @var object
44 : */
45 : var $geshi;
46 : /**
47 : * Array mit den zu ersetzenden Smilies
48 : * @access public
49 : * @var array
50 : */
51 : var $smilies;
52 : /**
53 : * HTML-Sonderzeichen maskieren
54 : * @access public
55 : * @var bool
56 : */
57 : var $htmlEntities = false;
58 : /**
59 : * Konstruktor.
60 : * Legt alle verwendbaren BBCodes fest.
61 : * Zum Hinzufügen weiterer Codes siehe Dokumentation auf
62 : * http://www.christian-seiler.de/projekte/php/bbcode/doc/de/.
63 : *
64 : * @access public
65 : * @param bool $htmlEntities Legt fest, ob HTML-Sonderzeichen im Text maskiert werden sollen
66 : * @param bool $images Legt fest, ob Bilder angezeigt werden sollen
67 : * @param bool $smilies Legt fest, ob Smilies als Icons dargestellt werden sollen
68 : * @param cool $code Legt fest, ob BBCode umgewandelt werden soll
69 : */
70 : function BBCode($htmlEntities = true, $images = true, $smilies = true, $code = true, $speller = false) {
71 0 : $bbcode = new StringParser_BBCode();
72 0 : if ($htmlEntities) {
73 0 : $this->htmlEntities = true;
74 0 : $bbcode->addParser(array("block", "inline", "link", "listitem", "code"), array(&$this, "toHTML"));
75 0 : }
76 0 : if ($code) {
77 0 : $bbcode->addParser(array("block", "inline", "listitem"), array(&$this, "convertBareLinks"));
78 0 : }
79 0 : $bbcode->addParser(array("block", "inline", "link", "listitem", "code"), "nl2br");
80 0 : if ($smilies) {
81 0 : $bbcode->addParser(array("block", "inline", "link", "listitem"), array(&$this, "replaceSmilies"));
82 0 : }
83 0 : $bbcode->addParser(array("block", "inline", "code", "listitem"), array(&$this, "convertMultipleSpaces"));
84 0 : if ($speller) {
85 0 : $sc = new SpellChecker("de");
86 0 : $bbcode->addParser(array("block", "inline", "listitem"), array(&$sc, "check"));
87 0 : }
88 0 : $bbcode->addFilter(STRINGPARSER_FILTER_PRE, array(&$this, "convertLineBreaks"));
89 0 : if ($code) {
90 0 : $bbcode->addCode('b', "simple_replace", null, array("start_tag" => "<strong>", "end_tag" => "</strong>"), "inline", array("block", "inline", "listitem", "link", "code"), array());
91 0 : $bbcode->setCodeFlag("b", "closetag", BBCODE_CLOSETAG_MUSTEXIST);
92 0 : $bbcode->addCode('i', "simple_replace", null, array("start_tag" => "<em>", "end_tag" => "</em>"), "inline", array("block", "inline", "listitem", "link", "code"), array());
93 0 : $bbcode->setCodeFlag("i", "closetag", BBCODE_CLOSETAG_MUSTEXIST);
94 0 : $bbcode->addCode('u', "simple_replace", null, array("start_tag" => "<span style='text-decoration: underline;'>", "end_tag" => "</span>"), "inline", array("block", "inline", "listitem", "link", "code"), array());
95 0 : $bbcode->setCodeFlag("u", "closetag", BBCODE_CLOSETAG_MUSTEXIST);
96 0 : $bbcode->addCode('-', "simple_replace", null, array("start_tag" => "<span style='text-decoration: line-through;'>", "end_tag" => "</span>"), "inline", array("block", "inline", "listitem", "link", "code"), array());
97 0 : $bbcode->setCodeFlag("-", "closetag", BBCODE_CLOSETAG_MUSTEXIST);
98 0 : $bbcode->addCode('tt', "simple_replace", null, array("start_tag" => "<span style='font-family: Courier New, monospace;'>", "end_tag" => "</span>"), "inline", array("block", "inline", "listitem", "link"), array());
99 0 : $bbcode->setCodeFlag("tt", "closetag", BBCODE_CLOSETAG_MUSTEXIST);
100 0 : $bbcode->addCode('code', "callback_replace?", array(&$this, "codeTag"), array("usecontent_param" => array("default", "language")), "code", array("block", "inline", "listitem"), array());
101 0 : $bbcode->setCodeFlag("code", "closetag", BBCODE_CLOSETAG_MUSTEXIST);
102 0 : $bbcode->addCode('quote', "simple_replace", null, array("start_tag" => "<blockquote><p><strong>Zitat:</strong></p>", "end_tag" => "</blockquote>"), "block", array("block"), array());
103 0 : $bbcode->setCodeFlag("quote", "closetag", BBCODE_CLOSETAG_MUSTEXIST);
104 0 : $bbcode->setCodeFlag("quote", "opentag.before.newline", BBCODE_NEWLINE_DROP);
105 0 : $bbcode->setCodeFlag("quote", "closetag.before.newline", BBCODE_NEWLINE_DROP);
106 0 : $bbcode->setCodeFlag("quote", "opentag.after.newline", BBCODE_NEWLINE_DROP);
107 0 : $bbcode->setCodeFlag("quote", "closetag.after.newline", BBCODE_NEWLINE_DROP);
108 0 : $bbcode->setCodeFlag("quote", "paragraphs", true);
109 0 : $bbcode->setCodeFlag("quote", "paragraph_type", BBCODE_PARAGRAPH_BLOCK_ELEMENT);
110 0 : $bbcode->addCode('color', "callback_replace", array(&$this, "colorTag"), array(), "inline", array("block", "inline", "listitem", "code"), array());
111 0 : $bbcode->setCodeFlag("color", "closetag", BBCODE_CLOSETAG_MUSTEXIST);
112 0 : $bbcode->addCode('url', "usecontent?", array(&$this, "urlTag"), array("usecontent_param" => "default"), "link", array("listitem", "block", "inline"), array("link"));
113 0 : $bbcode->setCodeFlag("url", "closetag", BBCODE_CLOSETAG_MUSTEXIST);
114 0 : $bbcode->setCodeFlag("url", "paragraph_type", BBCODE_PARAGRAPH_ALLOW_INSIDE);
115 0 : $bbcode->setCodeFlag("url", "closetag.before.newline", BBCODE_NEWLINE_DROP);
116 0 : $bbcode->setCodeFlag("url", "opentag.after.newline", BBCODE_NEWLINE_DROP);
117 0 : $bbcode->addCode('mail', "usecontent?", array(&$this, "mailTag"), array("usecontent_param" => "default"), "link", array("listitem", "block", "inline"), array("link"));
118 0 : $bbcode->setCodeFlag("mail", "closetag", BBCODE_CLOSETAG_MUSTEXIST);
119 0 : $bbcode->setCodeFlag("mail", "paragraph_type", BBCODE_PARAGRAPH_ALLOW_INSIDE);
120 0 : $bbcode->addCode('list', "simple_replace", null, array("start_tag" => "<ul>", "end_tag" => "</ul>"), "list", array("block", "listitem"), array());
121 0 : $bbcode->setCodeFlag("list", "closetag", BBCODE_CLOSETAG_MUSTEXIST);
122 0 : $bbcode->setCodeFlag("list", "paragraph_type", BBCODE_PARAGRAPH_BLOCK_ELEMENT);
123 0 : $bbcode->setCodeFlag("list", "opentag.before.newline", BBCODE_NEWLINE_DROP);
124 0 : $bbcode->setCodeFlag("list", "closetag.before.newline", BBCODE_NEWLINE_DROP);
125 0 : $bbcode->setCodeFlag("list", "closetag.after.newline", BBCODE_NEWLINE_DROP);
126 0 : $bbcode->addCode('*', "simple_replace", null, array("start_tag" => "<li>", "end_tag" => "</li>"), "listitem", array("list"), array());
127 0 : $bbcode->setCodeFlag("*", "closetag", BBCODE_CLOSETAG_OPTIONAL);
128 0 : $bbcode->setCodeFlag("*", "opentag.before.newline", BBCODE_NEWLINE_DROP);
129 0 : $bbcode->setCodeFlag("*", "closetag.before.newline", BBCODE_NEWLINE_DROP);
130 0 : $bbcode->addCode('noparse', // vom Forum benötigt
131 0 : "usecontent", array(&$this, "noparseTag"), array(), "noparse", array("block", "inline", "listitem", "link"), array());
132 :
133 0 : $bbcode->addCode('youtube', 'usecontent', array(&$this, 'youtubeTag'), array('usecontent_param' => 'default'), 'link', array('block', 'inline'), array('link'));
134 0 : $bbcode->setCodeFlag('youtube', 'paragraph_type', BBCODE_PARAGRAPH_ALLOW_INSIDE);
135 :
136 0 : $bbcode->addCode('myvideo', 'usecontent', array(&$this, 'myvideoTag'), array('usecontent_param' => 'default'), 'link', array('block', 'inline'), array('link'));
137 0 : $bbcode->setCodeFlag('myvideo', 'paragraph_type', BBCODE_PARAGRAPH_ALLOW_INSIDE);
138 :
139 0 : $bbcode->addCode('video', 'usecontent?', array(&$this, 'videoTag'), array('usecontent_param' => 'default'), 'link', array('block', 'inline'), array('link'));
140 0 : $bbcode->setCodeFlag('video', 'closetag', BBCODE_CLOSETAG_MUSTEXIST);
141 0 : $bbcode->setCodeFlag('video', 'paragraph_type', BBCODE_PARAGRAPH_ALLOW_INSIDE);
142 :
143 0 : $bbcode->addCode('tex', 'usecontent', array(&$this, 'texTag'), array('usecontent_param' => 'default'), 'image', array('listitem', 'block', 'inline'), array('link'));
144 0 : $bbcode->setCodeFlag('tex', 'closetag', BBCODE_CLOSETAG_MUSTEXIST);
145 :
146 0 : $bbcode->addCode('slideshare', 'usecontent', array(&$this, 'slideshareTag'), array('usecontent_param' => 'default'), 'link', array('block', 'inline'), array('link', 'listitem'));
147 0 : $bbcode->setCodeFlag('slideshare', 'closetag', BBCODE_CLOSETAG_MUSTEXIST);
148 :
149 0 : if ($images) {
150 0 : $bbcode->addCode('img', "usecontent", array(&$this, "imgTag"), array(), "image", array("listitem", "block", "inline", "link"), array());
151 0 : $bbcode->setCodeFlag("img", "closetag", BBCODE_CLOSETAG_MUSTEXIST);
152 0 : $bbcode->setCodeFlag("img", "closetag.before.newline", BBCODE_NEWLINE_DROP);
153 0 : $bbcode->setCodeFlag("img", "opentag.after.newline", BBCODE_NEWLINE_DROP);
154 0 : $bbcode->addCode('map', "callback_replace_single", array(&$this, "mapTag"), array(), "image", array("listitem", "block", "inline", "link"), array());
155 0 : $bbcode->setCodeFlag("map", "closetag", BBCODE_CLOSETAG_FORBIDDEN);
156 0 : }
157 0 : }
158 0 : $this->bbcode = $bbcode;
159 0 : $this->smilies = array(">:(" => "angry", ":D" => "biggrin", ":-D" => "biggrin", ":(" => "frown", ":-(" => "frown", "=)" => "gumble", "=-)" => "gumble", ":oah:" => "oah", ":o" => "oah", ":-o" => "oah", ":\\" => "prefect", ":-\\" => "prefect", ":/" => "prefect", ":-/" => "prefect", ":?" => "question", ":rolleyes:" => "rolleyes", ":roll:" => "rolleyes", ":)" => "smile", ":-)" => "smile", ":|" => "strange", ":-|" => "strange", ";)" => "wink", ";-)" => "wink");
160 0 : }
161 : /**
162 : * Ersetzt BBCode-Tags im übergebenen Text durch HTML-Code.
163 : *
164 : * @access public
165 : * @param string $text Zu parsender Text
166 : * @return string Mit HTML-Code formatierter Text
167 : */
168 : function parse($text) {
169 0 : return $this->bbcode->parse($text);
170 : }
171 : /**
172 : * Entfernt BBCode-Tags wie [quote], [code], [url...] etc. aus Texten
173 : *
174 : * @access public
175 : * @param string $text Text, aus dem die Tags entfernt werden sollen
176 : * @return string Text ohne Tags
177 : */
178 : function stripTags($text) {
179 0 : foreach(array_keys($this->bbcode->_codes) as $tag) {
180 0 : $tags[] = preg_quote($tag);
181 0 : }
182 0 : $text = preg_replace("/\[img\].+\[\/img\]/U", "", $text); // Bilder komplett entfernen
183 0 : $text = preg_replace("/\[\/?(".implode("|", $tags) .")((=.+)|( .+=.+))?\]/U", "", $text);
184 0 : return $text;
185 : }
186 : /**
187 : * Gibt einen Link auf die BBCode-Übersichtsseite zurück.
188 : *
189 : * @static
190 : * @access public
191 : * @param string $title Titel des Links, standardmäßig "Formatierungsmöglichkeiten"
192 : * @return string Link
193 : */
194 : function getTagOverviewLink($title = "Formatierungsmöglichkeiten") {
195 0 : return "<a href='".PATH_TO_ROOT."infos/bbcode.php' title='Formatierungsmöglichkeiten (Neues Fenster)' target='_blank'>$title</a>";
196 : }
197 : /**
198 : * Callback-Parser-Funktion
199 : * Wird vom Parser aufgerufen, um Smilies im Text durch entsprechende Bilder zu ersetzen.
200 : *
201 : * @access public
202 : * @param string $text Zu bearbeitender Text
203 : * @return string Text mit ersetzten Smilies
204 : */
205 : function replaceSmilies($text) {
206 0 : foreach(array_keys($this->smilies) as $smiley) {
207 0 : $smilies[] = preg_quote($smiley, "/");
208 0 : }
209 0 : if(isset($_SESSION["UserStyle"]) && $_SESSION["UserStyle"] == "fh_yaml") {
210 0 : return preg_replace("/(?<=^|\s)(".implode("|", $smilies) .")/em", '"<img src=\"".PATH_TO_ROOT."images/transparent.gif\" class=\"icon_forum_{$this->smilies[\'$1\']}_new\" alt=\"$1\" />"', $text);
211 : }
212 0 : return preg_replace("/(?<=^|\s)(".implode("|", $smilies) .")/em", '"<img src=\"".PATH_TO_ROOT."forum/templates/images/icon/{$this->smilies[\'$1\']}_new.png\" alt=\"$1\" />"', $text);
213 : }
214 : /**
215 : * Callback-Filter-Funktion
216 : * Wird als Pre-Filter angewendet, um Zeilenumbrüche zu vereinheitlichen.
217 : *
218 : * @access public
219 : * @param string $text Zu bearbeitender Text
220 : * @return string Bearbeiteter Text mit \n-Zeilenumbrüchen
221 : */
222 : function convertLineBreaks($text) {
223 0 : return preg_replace("/\015\012|\015|\012/", "\n", $text);
224 : }
225 : /**
226 : * Callback-Parser-Funktion
227 : * Wandelt Tabulatoren, Leerzeichen am Zeilenanfang und mehrere aufeinanderfolgende
228 : * Leerzeichen in um.
229 : *
230 : * @access public
231 : * @param string $text Zu bearbeitender Text
232 : * @return string Text mit festen Leerzeichen
233 : */
234 : function convertMultipleSpaces($text) {
235 0 : $text = str_replace("\t", " ", $text);
236 0 : $text = str_replace("\n ", "\n ", $text);
237 0 : $text = str_replace(" ", " ", $text);
238 0 : return $text;
239 : }
240 : /**
241 : * Callback-Parser-Funktion
242 : * Wandelt URLs und Email-Adressen ohne BBCode-Tags in Links um.
243 : *
244 : * @access public
245 : * @param string $text Zu bearbeitender Text
246 : * @return string Text mit funktionierenden Links
247 : */
248 : function convertBareLinks($text) {
249 : // Teile dieses Codes sind der Foren-Software Phorum (www.phorum.org) entnommen
250 0 : global $settings;
251 0 : $rnd = substr(md5($text.time()), 0, 6);
252 : // URLs mit Zufalls-String markieren
253 0 : $text = html_entity_decode($text, ENT_COMPAT, $settings["charset"]);
254 0 : $text = preg_replace("/((http|https|ftp):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),~%#]+)/i", ":$rnd:$1:/$rnd:", $text);
255 0 : $text = Data::toHTML($text, false);
256 : // Email-Adressen umwandeln
257 0 : $text = preg_replace("/([a-z0-9][a-z0-9\-_\.\+]+@[a-z0-9\-]+\.[a-z0-9\-\.]+[a-z0-9])/ie", '$this->mailTag("output", array(), "$1", array(), null)', $text);
258 0 : $match = array();
259 : // Satzzeichen um URLs ausnehmen
260 0 : if (preg_match_all("/:$rnd:(.+?):\/$rnd:/i", $text, $match)) {
261 0 : $urls = array_unique($match[1]);
262 0 : foreach($urls as $key => $url) {
263 0 : if (preg_match("/[^a-z0-9=&\/\+_]+$/i", $url, $match)) {
264 0 : $extra = $match[0];
265 0 : $true_url = substr($url, 0, -1*(strlen($match[0])));
266 0 : $text = str_replace("$url:/$rnd:", "$true_url:/$rnd:$extra", $text);
267 0 : $url = $true_url;
268 0 : }
269 0 : $text = preg_replace("/:$rnd:(".preg_quote($url, "/") ."):\/$rnd:/e", 'Utilities::validateURL("$1") ? $this->urlTag("output", array(), "$1", array(), null) : "$1"', $text);
270 0 : }
271 0 : }
272 0 : return $text;
273 : }
274 : /**
275 : * Callback-Parser-Funktion
276 : * Wird vom Parser aufgerufen, um Text außerhalb von BBCodes zu maskieren.
277 : *
278 : * @access public
279 : * @param string $text Text, der maskiert werden soll
280 : * @return string Maskierter Text
281 : */
282 : function toHTML($text) {
283 0 : return Data::toHTML((string)$text, false);
284 : }
285 : /**
286 : * Callback-Funktion
287 : * Ersetzt den [code]-Tag durch HTML-Code.
288 : *
289 : * @access public
290 : * @param string $action 'validate' oder 'output'
291 : * @param array $attributes Assoziatives Array mit im Starttag enthaltenen Attributen
292 : * @param string $content Inhalt, der von den Tags umschlossen wurde
293 : * @param array $params Parameter, die beim addCode()-Aufruf übergeben wurden
294 : * @param object $node_object Aktueller Knoten in der Baumstruktur
295 : */
296 : function codeTag($action, $attributes, $content, $params, $node_object) {
297 0 : global $settings;
298 0 : if ($action == "validate") {
299 0 : return true;
300 : }
301 0 : if (isset($attributes["language"]) || isset($attributes["default"])) {
302 0 : $lang = (isset($attributes["language"]) ? $attributes["language"] : $attributes["default"]);
303 0 : $source = str_replace("<br />", "", html_entity_decode($content, ENT_COMPAT, $settings["charset"]));
304 0 : if (isset($this->geshi)) {
305 0 : $this->geshi->set_language($lang);
306 0 : $this->geshi->set_source($source);
307 0 : } else {
308 0 : $this->geshi = new GeSHi($source, $lang);
309 0 : $this->geshi->set_header_type(GESHI_HEADER_NONE);
310 0 : $this->geshi->set_encoding($settings["charset"]);
311 : }
312 0 : if (!$this->geshi->error()) {
313 0 : $content = $this->geshi->parse_code();
314 0 : }
315 0 : }
316 0 : return "<code>$content</code>";
317 : }
318 : /**
319 : * Callback-Funktion
320 : * Ersetzt den [color]-Tag durch HTML-Code.
321 : *
322 : * @access public
323 : * @param string $action 'validate' oder 'output'
324 : * @param array $attributes Assoziatives Array mit im Starttag enthaltenen Attributen
325 : * @param string $content Inhalt, der von den Tags umschlossen wurde
326 : * @param array $params Parameter, die beim addCode()-Aufruf übergeben wurden
327 : * @param object $node_object Aktueller Knoten in der Baumstruktur
328 : */
329 : function colorTag($action, $attributes, $content, $params, $node_object) {
330 0 : if ($action == "validate") {
331 0 : return (bool)preg_match("/^#[0-9a-f]{6}$/i", $attributes["default"]);
332 : }
333 0 : return "<span style='color: $attributes[default];'>$content</span>";
334 : }
335 : /**
336 : * Callback-Funktion
337 : * Ersetzt den [img]-Tag durch HTML-Code.
338 : *
339 : * @access public
340 : * @param string $action 'validate' oder 'output'
341 : * @param array $attributes Assoziatives Array mit im Starttag enthaltenen Attributen
342 : * @param string $content Inhalt, der von den Tags umschlossen wurde
343 : * @param array $params Parameter, die beim addCode()-Aufruf übergeben wurden
344 : * @param object $node_object Aktueller Knoten in der Baumstruktur
345 : */
346 : function imgTag($action, $attributes, $content, $params, $node_object) {
347 0 : if ($action == "validate") {
348 0 : if (preg_match("/^http:\/\/".preg_quote($_SERVER["HTTP_HOST"].str_replace(SCRIPT_NAME, "common/makethumb.php?", $_SERVER["PHP_SELF"]), "/") ."/", $content)) {
349 0 : return true;
350 : }
351 : // Es sind nur direkt auf Bilder verweisende URLs zugelassen (jpg, jpeg, gif, png, bmp, ico)
352 : // und keine GET-Strings, um die Funktion sicherer gegen Cross-Site-Scripting zu machen.
353 : // Um zu vermeiden, dass Zeichen aus GET-Strings (?, &, =) URL-enkodiert (%xx) übergeben werden,
354 : // wird der String einmal dekodiert und dann sind auch keine %-Zeichen mehr zugelassen.
355 0 : return (bool)preg_match("/^(http|https|ftp):\/\/([a-z0-9\.\-@:]+)[a-z0-9;\/\:@\$\-_\.\+!\*'\(\),~ ]*?(\.jpg|\.jpeg|\.gif|\.png|\.bmp|\.ico)$/i", rawurldecode($content));
356 : }
357 0 : if ($this->htmlEntities) {
358 0 : $content = Data::toHTML($content, false);
359 0 : }
360 0 : return "<img src=\"$content\" alt='' />";
361 : }
362 : /**
363 : * Callback-Funktion
364 : * Ersetzt den [map]-Tag durch HTML-Code.
365 : *
366 : * @access public
367 : * @param string $action 'validate' oder 'output'
368 : * @param array $attributes Assoziatives Array mit im Starttag enthaltenen Attributen
369 : * @param string $content Inhalt, der von den Tags umschlossen wurde
370 : * @param array $params Parameter, die beim addCode()-Aufruf übergeben wurden
371 : * @param object $node_object Aktueller Knoten in der Baumstruktur
372 : */
373 : function mapTag($action, $attributes, $content, $params, $node_object) {
374 0 : require_once (PATH_TO_ROOT."mapdesigner/classes/class.mapdesigner.inc.php");
375 0 : global $db, $settings;
376 0 : $dbp = $settings["dbPrefix"];
377 0 : if ($action == "validate") {
378 0 : if (isset($attributes["default"])) {
379 0 : $mapIDs = $db->get_col("SELECT map_id FROM {$dbp}mapdesigner_map WHERE course_id='".$_SESSION["course"]."'");
380 0 : return $db->num_rows && in_array($attributes["default"], $mapIDs);
381 : }
382 0 : return false;
383 : }
384 0 : return MapDesigner::getMapHTML($attributes["default"]);
385 : }
386 : /**
387 : * Callback-Funktion
388 : * Ersetzt den [url]-Tag durch HTML-Code.
389 : *
390 : * @access public
391 : * @param string $action 'validate' oder 'output'
392 : * @param array $attributes Assoziatives Array mit im Starttag enthaltenen Attributen
393 : * @param string $content Inhalt, der von den Tags umschlossen wurde
394 : * @param array $params Parameter, die beim addCode()-Aufruf übergeben wurden
395 : * @param object $node_object Aktueller Knoten in der Baumstruktur
396 : */
397 : function urlTag($action, $attributes, $content, $params, $node_object) {
398 0 : if ($action == "validate") {
399 0 : return Utilities::validateURL(isset($attributes["default"]) ? $attributes["default"] : $content);
400 : }
401 0 : if (isset($attributes["default"])) {
402 0 : if ($this->htmlEntities) {
403 0 : $attributes["default"] = Data::toHTML($attributes["default"], false);
404 0 : }
405 0 : return "<a href=\"".$attributes["default"]."\" title=\"Link: ".$attributes["default"]."\">$content</a>";
406 : }
407 0 : $url = parse_url($content);
408 0 : $url = $url["host"];
409 0 : return "<a href=\"$content\" title=\"Link: $content\">$url</a>";
410 : }
411 : /**
412 : * Callback-Funktion
413 : * Ersetzt den [mail]-Tag durch HTML-Code.
414 : *
415 : * @access public
416 : * @param string $action 'validate' oder 'output'
417 : * @param array $attributes Assoziatives Array mit im Starttag enthaltenen Attributen
418 : * @param string $content Inhalt, der von den Tags umschlossen wurde
419 : * @param array $params Parameter, die beim addCode()-Aufruf übergeben wurden
420 : * @param object $node_object Aktueller Knoten in der Baumstruktur
421 : */
422 : function mailTag($action, $attributes, $content, $params, $node_object) {
423 0 : if ($action == "validate") {
424 0 : return preg_match("/^[a-z0-9\-_\.\+]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$/i", isset($attributes["default"]) ? $attributes["default"] : $content);
425 : }
426 0 : if (isset($attributes["default"])) {
427 0 : if ($this->htmlEntities) {
428 0 : $attributes["default"] = Data::toHTML($attributes["default"], false);
429 0 : }
430 0 : return "<a href=\"mailto:".$attributes["default"]."\">$content</a>";
431 : }
432 0 : return "<a href=\"mailto:$content\">$content</a>";
433 : }
434 : /**
435 : * Callback-Funktion
436 : * [noparse]-Tag des Forums, Inhalt wird nicht weiter verarbeitet.
437 : *
438 : * @access public
439 : * @param string $action 'validate' oder 'output'
440 : * @param array $attributes Assoziatives Array mit im Starttag enthaltenen Attributen
441 : * @param string $content Inhalt, der von den Tags umschlossen wurde
442 : * @param array $params Parameter, die beim addCode()-Aufruf übergeben wurden
443 : * @param object $node_object Aktueller Knoten in der Baumstruktur
444 : */
445 : function noparseTag($action, $attributes, $content, $params, $node_object) {
446 0 : if ($action == "validate") return true;
447 0 : return $content;
448 : }
449 : /**
450 : * Callback-Funktion
451 : * [youtube]youtube url[/youtube]
452 : *
453 : * @access public
454 : * @param string $action 'validate' oder 'output'
455 : * @param array $attributes Assoziatives Array mit im Starttag enthaltenen Attributen
456 : * @param string $content Inhalt, der von den Tags umschlossen wurde
457 : * @param array $params Parameter, die beim addCode()-Aufruf übergeben wurden
458 : * @param object $node_object Aktueller Knoten in der Baumstruktur
459 : */
460 : function youtubeTag($action, $attributes, $content, $params, $node_object) {
461 0 : if ($action == "validate") {
462 0 : if(Utilities::validateURL($content)) {
463 0 : return true;
464 : }
465 0 : return false;
466 : }
467 :
468 0 : if($action == 'output') {
469 0 : $code = substr ( strstr ( $content, 'v=' ), 2);
470 :
471 : return '
472 : <object width="480" height="295">
473 0 : <param name="movie" value="http://www.youtube.com/v/'.$code.'&hl=de&fs=1"></param>
474 : <param name="allowFullScreen" value="true"></param>
475 : <param name="allowscriptaccess" value="always"></param>
476 0 : <embed src="http://www.youtube.com/v/'.$code.'&hl=de&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed>
477 0 : </object>';
478 : }
479 :
480 0 : }
481 :
482 : /**
483 : * Callback-Funktion
484 : * [tex]TeX-Befehle[/tex]
485 : *
486 : * @access public
487 : * @param string $action 'validate' oder 'output'
488 : * @param array $attributes Assoziatives Array mit im Starttag enthaltenen Attributen
489 : * @param string $content Inhalt, der von den Tags umschlossen wurde
490 : * @param array $params Parameter, die beim addCode()-Aufruf uebergeben wurden
491 : * @param object $node_object Aktueller Knoten in der Baumstruktur
492 : */
493 : function texTag($action, $attributes, $content, $params, $node_object) {
494 0 : $strippedContent = strip_tags($content);
495 0 : return "<img src='/cgi-bin/mimetex.cgi?{$strippedContent}' alt='".Data::toHTML($strippedContent)."' />";
496 : }
497 :
498 : /**
499 : * Callback-Funktion
500 : * [slideshare]Volle Slideshare URL[/slideshare]
501 : *
502 : * @access public
503 : * @param string $action 'validate' oder 'output'
504 : * @param array $attributes Assoziatives Array mit im Starttag enthaltenen Attributen
505 : * @param string $content Inhalt, der von den Tags umschlossen wurde
506 : * @param array $params Parameter, die beim addCode()-Aufruf uebergeben wurden
507 : * @param object $node_object Aktueller Knoten in der Baumstruktur
508 : */
509 : function slideshareTag($action, $attributes, $content, $params, $node_object) {
510 0 : if ($action == "validate") {
511 0 : if(Utilities::validateURL($content)) {
512 0 : return true;
513 : }
514 0 : return false;
515 : }
516 0 : $sh = fopen($content,"r");
517 :
518 0 : $temp = NULL;
519 :
520 0 : $i = 0;
521 0 : while ($i < 25) {
522 0 : $temp .= fgets($sh, 4096);
523 0 : ereg('var slideshare_object(.*)</head>', $temp, $regs);
524 0 : $i++;
525 0 : }
526 :
527 0 : $string = strip_tags($regs[1]);
528 :
529 0 : preg_match_all("/totalSlides\":(.+?)\,/i",$string,$treffer,PREG_SET_ORDER);
530 0 : $totalslides = $treffer[0][1];
531 :
532 0 : preg_match_all("/doc\":\"(.+?)\"/i",$string,$treffer,PREG_SET_ORDER);
533 0 : $doc = $treffer[0][1];
534 :
535 0 : preg_match_all("/version_no\":\"(.+?)\"/i",$string,$treffer,PREG_SET_ORDER);
536 0 : $version_no = $treffer[0][1];
537 :
538 0 : preg_match_all("/presentationId\":(.+?)\,/i",$string,$treffer,PREG_SET_ORDER);
539 0 : $presentationId = $treffer[0][1];
540 :
541 0 : return '<embed width="477" height="390" flashvars="pvt=0&inContest=0&doc='.$doc.'&version_no='.$version_no.'&presentationId='.$presentationId.'&totalSlides='.$totalslides.'&startSlide=1&preview=no&useHttp=1" allowfullscreen="true" allowscriptaccess="always" quality="high" bgcolor="#FFFFFF" name="player" id="player" style="" src="http://static.slideshare.net/swf/player.swf" type="application/x-shockwave-flash"/><br /><br /><a href="'.$content.'" target="_blank">Watch on Slideshare</a>';
542 :
543 : }
544 :
545 :
546 :
547 : /**
548 : * Callback-Funktion
549 : * [myvideo]myvideo url[/myvideo]
550 : *
551 : * @access public
552 : * @param string $action 'validate' oder 'output'
553 : * @param array $attributes Assoziatives Array mit im Starttag enthaltenen Attributen
554 : * @param string $content Inhalt, der von den Tags umschlossen wurde
555 : * @param array $params Parameter, die beim addCode()-Aufruf übergeben wurden
556 : * @param object $node_object Aktueller Knoten in der Baumstruktur
557 : */
558 : function myvideoTag($action, $attributes, $content, $params, $node_object) {
559 0 : if ($action == "validate") {
560 0 : if(Utilities::validateURL($content)) {
561 0 : return true;
562 : }
563 0 : return false;
564 : }
565 0 : if($action == 'output')
566 0 : {
567 0 : $code = htmlspecialchars($content);
568 :
569 :
570 0 : $code = substr ( strstr ( $code, 'ch/' ), 3);
571 0 : $string = explode("/", $code);
572 0 : $code = $string[0];
573 :
574 :
575 : return "
576 0 : <object style='width:470px;height:406px;' width='470' height='406' type='application/x-shockwave-flash' data='http://www.myvideo.de/movie/".$code."'>
577 0 : <param name='movie' value='http://www.myvideo.de/movie/".$code."'></param>
578 : <param name='AllowFullscreen' value='true'></param>
579 : <param name='AllowScriptAccess' value='always'></param>
580 0 : <embed src='http://www.myvideo.de/movie/".$code."' width='470' height='406'></embed>
581 : </object>
582 : <br/><br/>
583 0 : ";
584 : }
585 0 : }
586 : /**
587 : * Callback-Funktion
588 : *
589 : * @access public
590 : * @param string $action 'validate' oder 'output'
591 : * @param array $attributes Assoziatives Array mit im Starttag enthaltenen Attributen
592 : * @param string $content Inhalt, der von den Tags umschlossen wurde
593 : * @param array $params Parameter, die beim addCode()-Aufruf übergeben wurden
594 : * @param object $node_object Aktueller Knoten in der Baumstruktur
595 : */
596 : function videoTag($action, $attributes, $content, $params, $node_object) {
597 0 : global $comments;
598 0 : if ($action == 'validate') return Utilities::validateURL(isset($attributes['default']) ? $attributes['default'] : $content);
599 0 : if (isset($content)) {
600 0 : $url = parse_url($content);
601 0 : $param = array();
602 0 : switch ($url['host']) {
603 0 : case 'www.youtube.com':
604 0 : $param['default'] = substr($content, strrpos($content, '=') +1, strlen($content));
605 0 : return $this->youtubeTag(null, $param, $content, null, null);
606 : break;
607 :
608 0 : case 'www.myvideo.de':
609 0 : $param['default'] = substr($content, strrpos($content, '/') +1, strlen($content));
610 0 : return $this->myvideoTag(null, $param, $content, null, null);
611 : break;
612 0 : }
613 0 : }
614 0 : }
615 : }
|